package com.wuyou.designPatterns.interpreter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description <command list> ::= <command>* end
 * @Author 无忧
 * @Date 2024/10/20 21:51
 */
public class CommandListNode extends Node{

    private List list = new ArrayList<>();

    @Override
    public void parse(Context context) throws ParseException {
        while (true){
            if (context.currentToken() == null) {
                throw new ParseException("Missing 'end'");
            } else if (context.currentToken().equals("end")) {
                context.skipToken("end");
                break;
            }else {
                Node commandNode = new CommandNode();
                commandNode.parse(context);
                list.add(commandNode);
            }
        }
    }

    public String toString(){
        return list.toString();
    }
}
